<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>简易弹层</title>
    <style>
        *{
            margin: 0px;
        }
        #div1{
            position: fixed;
            width: 100%;
            height: 100%;
            background: aqua;
        }
        button{
            float:left;
            margin-top: 20%;
            margin-left: 50%;
        }
        #div2{
            position: fixed;
            width: 100%;
            height: 100%;
            background: black;
            opacity: 0.8;
        }
        .hide{
            display: none;
        }
        #div3{
            position: fixed;
            width: 20%;
            height: 20%;
            background: blue;
            margin-top: 20%;
            margin-left: 40%;
        }
    </style>
</head>
<body>
    <div id="div1">
        <button id="button1" type="button" value="click" onclick="show()">点我</button>
    </div>
    <div id="div2" class="div hide"></div>
    <div id="div3" class="div hide">
            <button id="button2" type="button" value="cancel" onclick="cancel()">点我</button>
    </div>

    <script>
        function show() {
            var ele = document.getElementsByClassName("div");
            for(i=0;i<ele.length;i++){
                console.log(ele[i]);
                ele[i].classList.remove("hide")

            }

        }

        function cancel() {
            var ele = document.getElementsByClassName("div");
            for(i=0;i<ele.length;i++){
                ele[i].classList.add("hide")
            }

        }
    </script>
</body>
</html>